package cn.wanda.bi.sunshine.platform.server.service;

import cn.wanda.bi.sunshine.platform.server.aspect.Logging;
import cn.wanda.bi.sunshine.platform.server.bean.mapper.UserLabelAuthMenuMapper;
import cn.wanda.bi.sunshine.platform.server.bean.model.*;
import cn.wanda.bi.sunshine.platform.server.controller.response.common.ListResponse;
import cn.wanda.bi.sunshine.platform.server.controller.response.common.SimpleResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by wangfupeng1
 */
@Service
public class UserLabelAuthMenuService implements Logging {

    public static final Logger logger = LoggerFactory.getLogger(UserLabelAuthMenuService.class);


    @Autowired
    private UserLabelAuthMenuMapper userLabelAuthMenuMapper;

    //增加
    public SimpleResponse<UserLabelAuthMenu> addUserLabelAuthMenu(UserLabelAuthMenu userLabelAuthMenu) {
        userLabelAuthMenuMapper.insert(userLabelAuthMenu);
        return SimpleResponse.success(userLabelAuthMenu);
    }

    //根据PageId进行查询
	@Cacheable(value = "cache:userlabelauthmenu", key = "'cache:userlabelauthmenu:id:'+#id")
    public SimpleResponse<UserLabelAuthMenu> queryUserLabelAuthMenuById(Integer id) {
        UserLabelAuthMenu userLabelAuthMenu = userLabelAuthMenuMapper.selectByPrimaryKey(id);
        return SimpleResponse.success(userLabelAuthMenu);
    }

	//根据page id进行修改
	@CacheEvict(value = "cache:userlabelauthmenu", key = "'cache:userlabelauthmenu:id:'+#userLabelAuthMenu.getId()")
	public SimpleResponse<UserLabelAuthMenu> updateUserLabelAuthMenu( UserLabelAuthMenu userLabelAuthMenu) {

        userLabelAuthMenuMapper.updateByPrimaryKeySelective(userLabelAuthMenu);

        return SimpleResponse.success(userLabelAuthMenu);
    }
	
    //删除page
	@CacheEvict(value = "cache:userlabelauthmenu", key = "'cache:userlabelauthmenu:id:'+#userLabelAuthMenu.getId()")
    public SimpleResponse<UserLabelAuthMenu> deleteUserLabelAuthMenu( Integer id) {
         userLabelAuthMenuMapper.deleteByPrimaryKey(id);
        return SimpleResponse.success();
    }
	
    //查询所有Page
    public ListResponse<UserLabelAuthMenu> queryUserLabelAuthMenuList(Integer index, Integer limit) {
        UserLabelAuthMenuExample userLabelAuthMenuExample = new UserLabelAuthMenuExample();
        userLabelAuthMenuExample.setOffset(index * limit - limit);
        userLabelAuthMenuExample.setLimit(limit);
        List<UserLabelAuthMenu> userLabelAuthMenus = userLabelAuthMenuMapper.selectByExample(userLabelAuthMenuExample);
        int count = userLabelAuthMenuMapper.countByExample(new UserLabelAuthMenuExample());
        return ListResponse.success(userLabelAuthMenus,count,index,limit);
    }


}
